package com.mzy.linear_struct.ks;


import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author: mizy3
 * @Date: 2024/09/04/下午10:36
 * @Description:
 */
public class 并发接收文件 {

    public static void main(String[] args) throws Exception {
        ServerSocket serverSocket = new ServerSocket(8888);
        ThreadPoolExecutor pool = new ThreadPoolExecutor(10, 20,
                3, TimeUnit.SECONDS, new LinkedBlockingDeque<>(),
                new ThreadPoolExecutor.AbortPolicy());
        try {
            while (true){
                Socket socket = serverSocket.accept();
                pool.submit(new FileHandler(socket));
            }
        }catch (Exception e){

        }finally {
            serverSocket.close();
        }
    }
}
class FileHandler implements Runnable{

    private Socket socket;

    public FileHandler(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {
            InputStream inputStream = socket.getInputStream();

        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}